package com.yphone.ui.login.presenter;

import android.text.TextUtils;
import android.util.Log;

import com.iiordanov.bVNC.App;
import com.yphone.net.IUIDataListener;
import com.yphone.net.bean.BaseResultWrapper;
import com.yphone.tools.MyLog;
import com.yphone.tools.SharepreferenConstants;
import com.yphone.ui.dialog.CommSmallLoadingDialog;
import com.yphone.ui.login.bean.request.LoginRequestInfo;
import com.yphone.ui.login.bean.request.PhoneRegisterRequestInfo;
import com.yphone.ui.login.contract.RegisterActivityContract;
import com.yphone.ui.login.model.LoginActivityModel;
import com.yphone.ui.login.model.RegisterActivityModel;
import com.yphone.ui.login.respone.UserInfo;
import com.yphone.utils.ToastUtils;
import com.zzkj.yunphone.R;

public class RegisterActivityPresenter implements RegisterActivityContract.IPresenter {
    private IUIDataListener iuiDataListener = new IUIDataListener() {
        public void uiDataSuccess(Object object) {
            BaseResultWrapper<UserInfo> userinfoWrapper = (BaseResultWrapper) object;
            if (userinfoWrapper == null){
                ToastUtils.showLong(App.getContext().getString(R.string.server_error));
                CommSmallLoadingDialog.dismissDialog();
                return;
            }
            if (userinfoWrapper.code != 1) {
                MyLog.d(RegisterActivityPresenter.class.getSimpleName(), "注册失败！");
                if (!TextUtils.isEmpty(userinfoWrapper.msg)) {
                    ToastUtils.showLong((CharSequence) userinfoWrapper.msg);
                }
                CommSmallLoadingDialog.dismissDialog();
                return;
            }
            MyLog.d(RegisterActivityPresenter.class.getSimpleName(), "注册成功！:" + ((UserInfo) userinfoWrapper.data).toString());
            LoginRequestInfo loginRequestInfo = new LoginRequestInfo();
            loginRequestInfo.username = RegisterActivityPresenter.this.mPhoneNumber;
            loginRequestInfo.password = RegisterActivityPresenter.this.mPassword;
//            loginRequestInfo.LastReadTime = MySharepreferenceUtil.getSharePreLong(RegisterActivityPresenter.this.mIView.getContext(), SharepreferenConstants.SHARE_NAME_FILE, SharepreferenConstants.NOTICE_MESSAGE_READ_LAST_TIME, 0);
//            loginRequestInfo.BulletinId = SharepreferenceUtils.getSharedPreferencesToInt(SharepreferenConstants.BULLETINID, 0);
            new LoginActivityModel(RegisterActivityPresenter.this.mIView.getContext()).requestLoginToSer(loginRequestInfo);
        }

        public void uiDataError(Exception error) {
            MyLog.d(RegisterActivityPresenter.class.getSimpleName(), "注册异常！"+ Log.getStackTraceString(error));
            CommSmallLoadingDialog.dismissDialog();
        }
    };
    /* access modifiers changed from: private */
    public RegisterActivityContract.IView mIView;
    private RegisterActivityModel mImodel;
    /* access modifiers changed from: private */
    public String mPassword;
    /* access modifiers changed from: private */
    public String mPhoneNumber;

    public RegisterActivityPresenter(RegisterActivityContract.IView IView) {
        this.mIView = IView;
        this.mImodel = new RegisterActivityModel();
    }

    public void registerRequest(String phone_number, String password, String verificationCode, String inviteCode) {
        this.mPhoneNumber = phone_number;
        this.mPassword = password;
        PhoneRegisterRequestInfo info = new PhoneRegisterRequestInfo();
        info.phone = phone_number;
        info.password = password;
        info.code = verificationCode;
        info.username = phone_number;
        info.agent_num = inviteCode;
        this.mImodel.registerRequest(this.iuiDataListener, info);
    }

    public void start() {
    }

    public void destory() {
        this.mImodel.destory();
    }
}